// PNG半透明图片的问题
if(/msie 6/.test(window.navigator.userAgent.toLowerCase())){
	function correctPNG(){
	    var arVersion = navigator.appVersion.split("MSIE")
	    var version = parseFloat(arVersion[1])
	    if ((version >= 5.5) && (document.body.filters))
	    {
	       for(var j=0; j<document.images.length; j++)
	       {
	          var img = document.images[j]
	          var imgName = img.src.toUpperCase()
	          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	          {
	             var imgID = (img.id) ? "id='" + img.id + "' " : ""
	             var imgClass = (img.className) ? "class='" + img.className + "' " : ""
	             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
	             var imgStyle = "display:inline-block;" + img.style.cssText
	             if (img.align == "left") imgStyle = "float:left;" + imgStyle
	             if (img.align == "right") imgStyle = "float:right;" + imgStyle
	             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
	             var strNewHTML = "<span " + imgID + imgClass + imgTitle
	             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
	             img.outerHTML = strNewHTML
	             j = j-1
	          }
	       }
	    }    
	}
	window.attachEvent("onload", correctPNG);

	// IE6下默认不缓存背景图片
	try {
	  document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
}

if(!window.JSON)window.JSON = {};

// for IE7- 不报错
if(!window.Element)window.Element = function(){};

// for IE8-
if(!window.addEventListener){
	/**
	 * @param {String} eventName 事件名称，不要带 on 开头
	 * @param {Function} eventHandler 事件处理器
	 */
	window.addEventListener = Element.prototype.addEventListener = function(eventType, funcHandle, useCapture) {
        var element = this;
        if (eventType == "input") { eventType = "propertychange"; }
        
        // 兼容处理
        var eventHandle = function(event) {
            event = event || window.event || {};
            
            if (!event.target) event.target = event.srcElement;        
            if (!event.preventDefault) event.preventDefault = function() {
                    event.returnValue = false;
            };
            
            if (eventType == "propertychange" && event.propertyName !== "value") return;
            
            return funcHandle.call(element, event);
        };
        eventHandle.initFuncHandle = funcHandle;
        

        element.attachEvent("on" + eventType, eventHandle);// event bind
        
        // event store
        if (element["event" + eventType])
        	element["event" + eventType].push(eventHandle);
        else 
        	element["event" + eventType] = [eventHandle];
    }
}

if(!window.postMessage){
	console.warn('不支持 postMessage');
	window.postMessage = function(event){
		var e = {
			data : event
		};
		render(e);
	}
}

// for IE7- = addEventListener + MyUtils
if(!document.querySelector) {
	function fDomExtend(collection) {
        // collection extend some dom method
        for (var element, i = 0, len = collection.length; i < len; ++i){
        	element = collection[i];

			for (var key in oDomExtend)
				element[key] = oDomExtend[key].bind(element);
			for (var key in addElementMethod)
				element[key] = addElementMethod[key].bind(element);
        }
        return collection;
    };

    document.querySelector = function(selector) {
        return document.querySelectorAll(selector)[0] || null;
    }
    document.querySelectorAll = function(selector) {
    	if(!window.Sizzle)throw 'Sizzle.js 未加载！';
        var collection = Sizzle(selector);                
        return fDomExtend(collection);        
    }

	/**
     * dom method that extend
    */
    var oDomExtend = {
        // selector realtive
        querySelector: function(selector) {
            return oDomExtend.querySelectorAll.call(this, selector)[0] || null;
        },
        querySelectorAll: function(selector) {
            return fDomExtend(Sizzle(selector, this));
        },

        // addEventListener
        addEventListener : Element.prototype.addEventListener,
        on : Element.prototype.addEventListener
    };
}

var isNEED = window.navigator.isIE6 || window.navigator.isIE7;
window.elWrapper = function(el){
	if(!isNEED)return el;
	return fDomExtend([el])[0];
}

if (!("addEventListener" in document.createElement("div"))) {
// 劫持 document.createElement 方法
 	var _old_createElement = document.createElement;
 	document.createElement = function(el){
 		el = _old_createElement(el);
 		return elWrapper(el);
 	}
}
